﻿@using WsdShop.Model.Enum;
@{
    Layout = null;
}

<style>
    .my-drop-zone {
        border: dotted 3px lightgray;
    }

    .nv-file-over {
        border: dotted 3px red;
    }
    /* Default class applied to drop zones on over */
    .another-file-over-class {
        border: dotted 3px green;
    }

    html, body {
        height: 100%;
    }

    canvas {
        background-color: #f3f3f3;
        -webkit-box-shadow: 3px 3px 3px 0 #e3e3e3;
        -moz-box-shadow: 3px 3px 3px 0 #e3e3e3;
        box-shadow: 3px 3px 3px 0 #e3e3e3;
        border: 1px solid #c3c3c3;
        height: 100px;
        margin: 6px 0 0 6px;
    }

    .ngdialog.ngdialog-theme-plain .ngdialog-content {
        width: 55% !important;
    }

    .form-horizontal .form-group {
        margin-left: 0;
        margin-right: 0;
    }

    .note-image-input {
        margin-bottom: 15px;
    }
</style>
<div ng-controller="SendOrderInfoController">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <form name="formValidate" ng-submit="submitForm()" novalidate="" class="form-validate form-horizontal">
                    <!-- START 基本信息panel-->
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>基本信息</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>

                                    <tr>
                                        <td class="text-right">订单号:</td>
                                        <td class="text-center">{{Order.OrderNo}}</td>
                                        <td class="text-right">下单时间:</td>
                                        <td class="text-center">{{Order.AddTime}}</td>
                                    </tr>
                                    <tr>
                                        <td class="text-right">配送方式:</td>
                                        <td class="text-center">{{Order.TemplateName}}                        </td>
                                        <td class="text-right">配送费用:</td>
                                        <td class="text-center">{{Order.PostageMoney}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- 收货信息-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>收货信息</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td class="text-right">收货人:</td>
                                        <td class="text-center">{{Order.ReceiveName}}</td>
                                        <td class="text-right">联系方式:</td>
                                        <td class="text-center">{{Order.ReceivePhone}}</td>
                                    </tr>
                                    <tr>
                                        <td class="text-right">地址:</td>
                                        <td class="text-center">{{Order.Province}},{{Order.City}},{{Order.Area}},{{Order.ReceiveAddress}}</td>
                                        <td class="text-right">邮编:</td>
                                        <td class="text-center">{{Order.Zipcode}}</td>
                                    </tr>
                                    <tr>
                                        <td class="text-right">发票抬头</td>
                                        <td class="text-center">{{Order.InvoiceTitle}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!--商品信息-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>商品信息</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td class="text-left">商品</td>
                                        <td class="text-left">规格</td>
                                        <td class="text-right">数量</td>
                                        <td class="text-right">单品价格</td>
                                        <td class="text-right">会员折扣价</td>
                                        <td class="text-right">选择发货</td>
                                    </tr>
                                    <tr ng-repeat="item in OrderDetail">
                                        <td class="text-left">
                                            {{item.ProductName}}
                                        </td>
                                        <td class="text-left">{{item.SpecName}}</td>
                                        <td class="text-right">{{item.ProductCount}}</td>
                                        <td class="text-right">{{item.ProductPrice}}</td>
                                        <td class="text-right">{{item.DiscountPrice}}</td>
                                        <td class="text-right" ng-show="item.SendStatus==0&&item.ReturnDes==''"><label><input type="checkbox" ng-click="updateSelection($event,item.Id)"></label></td>
                                        <td class="text-right" ng-show="item.SendStatus!=0||item.ReturnDes!=''">{{item.ReturnDes==''?item.SendStatusDes:item.ReturnDes}}</td>
                                    </tr>

                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!--发货信息-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}" ng-show="Order.SendStatus!=@((int)OrderSendStatus.已发货)">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>发货信息</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td class="text-right col-sm-2"><p class="margin">快递公司：</p></td>
                                        <td colspan="3">
                                            <input class="input-sm" name="ShippingName" id="ShippingName" ng-model="Model.ShippingName">

                                        </td>

                                    </tr>
                                    <tr>
                                        <td class="text-right col-sm-2"><p class="margin">配送单号：</p></td>
                                        <td colspan="3">
                                            <input class="input-sm" name="InvoiceNo" id="InvoiceNo" ng-model="Model.InvoiceNo">
                                            
                                        </td>
                                        
                                    </tr>
                                    <tr>
                                        <td class="text-right col-sm-2"><p class="margin">操作备注：</p></td>
                                        <td colspan="3">

                                            <textarea name="Note" placeholder="请输入操作备注" ng-model="Model.Note" rows="3" class="form-control"></textarea>
                                        </td>

                                    </tr>
                                    <tr>
                                        <td class="text-right col-sm-2"><p class="margin">当前可执行操作：</p></td>
                                        <td colspan="3">
                                            <div class="input-group">
                                                <button class="btn btn-primary margin" type="button" ng-click="goSend()">
                                                    确认发货
                                                </button>
                                            </div>
                                        </td>

                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <!--操作记录-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>发货记录</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td class="text-center">操作者</td>
                                        <td class="text-center">发货时间</td>
                                        <td class="text-center">发货单号</td>
                                        <td class="text-center">收货人</td>
                                        <td class="text-center">快递公司</td>
                                        <td class="text-center">备注</td>
                                        <td class="text-center">查看</td>
                                    </tr>
                                    <tr ng-repeat="item in OrderRecord">
                                        <td class="text-center">{{item.AddUserName}}</td>
                                        <td class="text-center">{{item.AddTime}}</td>
                                        <td class="text-center">{{item.InvoiceNo}}</td>
                                        <td class="text-center">{{item.Consignee}}</td>
                                        <td class="text-center">{{item.ShippingName}}</td>
                                        <td class="text-center">{{item.Note}}</td>
                                        <td class="text-center"><a href="http://www.kuaidi100.com/" target="_blank">查看物流</a></td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="text-right">
                        <button type="button" class="btn btn-warning" ng-click="cancel()">返回列表</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    App.controller('SendOrderInfoController', ["$scope", "$state", "$http", "$stateParams", "Notify", 'ngTableParams', 'ngTableDataService', 'ngDialog', '$filter', '$rootScope','$window',
        function ($scope, $state, $http, $stateParams, Notify, ngTableParams, ngTableDataService, ngDialog, $filter, $rootScope,$window) {
            'use strict';
            $scope.submitted = false;
            $scope.isLoading = true;
            $scope.selected = []; 
            $scope.Model={};
            $scope.validateInput = function (name, type) {
                var input = $scope.formValidate[name];
                return (input.$dirty || $scope.submitted) && input.$error[type];
            };




            //数据初始化
            var GetOrderModel = function () {
                $http.post("/Order/GetOrderModel", { id: $stateParams.id }).then(function (response) {
                    $scope.Order = response.data.data;
                    if (!$scope.Order) {
                        Notify.alert("该订单不存在", { status: 'warning' });
                        $state.go('admin.orderInfoManage');
                        $scope.Order = {};
                    }

                    $scope.isLoading = false;
                });
            }
            var GetOrderDetail = function () {
                $http.post("/Order/GetOrderDetail", { orderId: $stateParams.id }).then(function (response) {
                    $scope.OrderDetail = response.data.data;
                });
            }
            var GetSendRecord = function () {
                $http.post("/Order/GetSendOrderRecord", { orderId: $stateParams.id }).then(function (response) {
                    $scope.OrderRecord = response.data.data;
                });
            }
            GetOrderModel();
            GetOrderDetail();
            GetSendRecord();

            //返回列表
            $scope.cancel = function () {
                $state.go("app.sendOrder");
            }
            

            
  
            var updateSelected = function (action, id) {
                console.log(action);
                if(action == 'add' && $scope.selected.indexOf(id) == -1){ 
                    $scope.selected.push(id); 
                } 
                if(action == 'remove' && $scope.selected.indexOf(id)!=-1){ 
                    var idx = $scope.selected.indexOf(id); 
                    $scope.selected.splice(idx,1); 
                }
                console.log($scope.selected);
            } 
  
            $scope.updateSelection = function ($event, id) {
                console.log(id);
                var checkbox = $event.target; 
                var action = (checkbox.checked?'add':'remove'); 
                updateSelected(action,id); 
            } 

           
            //去发货
            $scope.goSend=function()
            {
                if($scope.selected.length==0)
                {
                    Notify.alert("请选择商品", { status: 'warning' });   
                    return;
                }

                if ($scope.Model.InvoiceNo == undefined || $scope.Model.InvoiceNo == "") {
                    Notify.alert("请输入配送单号", { status: 'warning' });
                    return;
                }

                if ($scope.Model.ShippingName == undefined || $scope.Model.ShippingName == "")
                {
                    Notify.alert("请输入快递公司", { status: 'warning' });   
                    return;
                }

                $scope.Model.OrderId = $scope.Order.Id;
                $scope.Model.OrderNo = $scope.Order.OrderNo;
                $scope.Model.MemberId = $scope.Order.MemberId;
                $scope.Model.Province =$scope.Order.ReceiveProvince;
                $scope.Model.City =$scope.Order.ReceiveCity;
                $scope.Model.District =$scope.Order.ReceiveArea;
                $scope.Model.Address =$scope.Order.ReceiveAddress;
                $scope.Model.Consignee =$scope.Order.ReceiveName;
                $scope.Model.Zipcode =$scope.Order.Zipcode;
                $scope.Model.Mobile =$scope.Order.ReceivePhone;
                $scope.Model.ShippingPrice =$scope.Order.PostageMoney;
                //$scope.Model.ShippingName =$scope.Order.TemplateName;

                $http.post("/Order/AddDelivery", { model: $scope.Model,ids:$scope.selected }).then(function (response) {
                    if(response.data.isSuccess)
                    {
                        Notify.alert('操作成功!', { status: 'success' });
                        GetOrderModel();
                        GetOrderDetail();
                        GetSendRecord();
                    }
                    else
                    {
                        Notify.alert(response.data.msg, { status: 'warning' });
                        $scope.isLoading = false;
                    }
                });
            }

        }]);
</script>
